<?php
/*
 * 百度资讯类型的siteMap文件
 */
class Libs_SiteMap_News extends Libs_SiteMap_Base{
    function __construct(){
		$this->head = '<?xml version="1.0" encoding="UTF-8"?>';
		$this->head .="\n";
		$this->head .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
                                xmlns:n="http://www.google.com/schemas/sitemap-news/0.9">';
		$this->head .="\n";
		$this->footer = '</urlset>';
    }
    /**
     * 生成链接区域
     * @param array $dataArr 数据数组 loc date title keywords
     */
    function createSection(&$dataArr){
        $outstr = '';
        foreach ($dataArr as $data) {
        	$outstr .= "<url>\n";
			$outstr .= "<loc>".$data['loc']."</loc>\n";
        	$outstr .= "<n:news>\n";
        	$outstr .= "<n:publication><n:name>".iconv('GBK','UTF-8','中关村在线')."</n:name><n:language>zh-cn</n:language></n:publication>\n";
         	if(!empty($data['date']))$outstr .= "<n:publication_date>".$data['date']."</n:publication_date>\n";
       		$outstr .= "<n:title><![CDATA[".iconv('GBK','UTF-8',$data["title"])."]]></n:title>\n";
			$outstr .= "<n:keywords><![CDATA[".iconv('GBK','UTF-8',$data["keywords"])."]]></n:keywords>\n";
        	$outstr .= "</n:news>\n";
        	$outstr .= "</url>\n";
        }
        return $outstr;
    }

}


?>
